<?php
namespace App\Http\Controllers\Web;
use App\Http\Controllers\Web\BaseController;
use App\Repository\Repositories\Interfaces\RegionsRepository;
use Illuminate\Http\Request;
use App\ConstDir\ErrorConst;


class RegionsController extends BaseController
{
    protected $regions_repo;
    protected $request;

    public function __construct(RegionsRepository $regions_repo , Request $request)
    {
        $this->regions_repo = $regions_repo;
        $this->request = $request;
    }

    /*
     * 通过父类ID查询旗下所属地区列表
     */
    public function getListAddress($parent_id){

        $data = $this->regions_repo->getListAddress($parent_id);

        if($data){
            return $this->success(ErrorConst::SUCCESS_CODE_MSG,$data);
        }else{
            return $this->error(ErrorConst::BASE_ERROR_MSG, ErrorConst::BASE_ERROR);
        }

    }


    /*
    * 检验验证码是否正确
    */
    public function VerifyCode(Request $request){

        $this->validate($request, [
            'phone' => 'required|numeric',
            'code' => 'required|numeric'
        ]);
        $data = $request->all();
        $code = \Cache::get($data['phone']);
        if(!$code){
            return $this->error(ErrorConst::SMS_CODE_NO_MSG,ErrorConst::SMS_CODE_NO_CODE);
        }
        if($code != $data['code']){
            return $this->error(ErrorConst::SMS_CODE_ERROR_MSG,ErrorConst::SMS_CODE_ERROR_CODE);
        }else{
            return $this->success(ErrorConst::SUCCESS_CODE_MSG);
        }


    }



}
